import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
  path: '/',
  name: 'Pages',
  redirect: '/home',
  component: () => import('../views/pages.vue'),
  children: [{
    path: 'home',
    name: 'Home',
    component: () => import('../views/home/home.vue'),
    meta: {
      title: 'DDS·C设计师俱乐部'
    },
    children: [{
      path: 'activity',
      name: 'Activity',
      component: () => import('../views/home/activity.vue'),
      meta: {
        title: '活动'
      },
      children: [{
        path: 'detail/:id',
        name: 'ActivityDetail',
        component: () => import('../views/home/activity/detail.vue'),
        meta: {
          title: '活动详情'
        }
      }]
    },
    {
      path: 'detail/:id',
      name: 'HomeActivityDetail',
      component: () => import('../views/home/activity/detail.vue'),
      meta: { title: '活动详情' }
    },
    {
      path: 'designer-detail',
      name: 'DesignerDetail',
      component: () => import('../views/designer/home-page.vue'),
      meta: {
        title: '设计师主页'
      },
      children: [
        {
          path: 'case-detail',
          name: 'DesignerCaseDetail',
          component: () => import('../views/designer/case-detail.vue'),
          meta: { title: '案例详情' }
        }
      ]
    },
    {
      path: 'brand-detail',
      name: 'BrandDetail',
      component: () => import('../views/brand/home-page.vue'),
      meta: { title: '品牌主页' }
    },
    {
      path: 'search',
      name: 'Search',
      component: () => import('../components/search/search.vue'),
      meta: {
        title: '搜索'
      }
    }
    ]
  }, {
    path: 'designer',
    name: 'Designer',
    component: () => import('../views/designer/designer.vue'),
    meta: {
      title: '设计师'
    },
    children: [{
      path: 'filtrate',
      name: 'Filtrate',
      component: () => import('../views/designer/filtrate.vue'),
      meta: {
        title: '筛选'
      }
    },
    {
      path: 'poster',
      name: 'Poster',
      component: () => import('../views/designer/poster.vue'),
      meta: {
        title: '权益海报'
      },
      children: [{
        path: 'application',
        name: 'Application',
        component: () => import('../views/designer/application.vue'),
        meta: {
          title: '设计师入驻申请'
        },
        children: [
          {
            path: 'protocol',
            name: 'Protocal',
            component: () => import('../views/designer/protocol.vue'),
            meta: { title: '设计师入驻协议' }
          }
        ]
      }]
    },
    {
      path: 'home-page',
      name: 'HomePage',
      component: () => import('../views/designer/home-page.vue'),
      meta: {
        title: '设计师主页'
      },
      children: [{
        path: 'case-detail',
        name: 'CaseDetail',
        component: () => import('../views/designer/case-detail.vue'),
        meta: {
          title: '案例详情'
        }
      }]
    }
    ]
  }, {
    path: 'brand',
    name: 'Brand',
    component: () => import('../views/brand/brand.vue'),
    meta: {
      title: '品牌'
    },
    children: [{
      path: 'home-page',
      name: 'BrandHomePage',
      component: () => import('../views/brand/home-page.vue'),
      meta: {
        title: '品牌主页'
      }
    }]
  }, {
    path: 'my',
    name: 'My',
    component: () => import('../views/my/my.vue'),
    meta: {
      title: '我的'
    },
    children: [{
      path: 'edit',
      name: 'Edit',
      component: () => import('../views/my/edit.vue'),
      meta: {
        title: '编辑资料'
      }
    },
    {
      path: 'message',
      name: 'Message',
      component: () => import('../views/my/message.vue'),
      meta: {
        title: '消息'
      },
      children: [
        {
          path: 'designer',
          name: 'MsgDesigner',
          component: () => import('../views/my/my-homapage/edit-msg.vue'),
          meta: {
            title: '编辑资料'
          }
        },
        {
          path: 'order-detail',
          name: 'MsgOrderDetail',
          component: () => import('../views/my/exchange-center/order-detail.vue'),
          meta: {
            title: '订单详情'
          }
        },
        {
          path: 'msg-detail',
          name: 'MsgDetail',
          component: () => import('../views/my/message/detail'),
          meta: {
            title: '消息详情'
          }
        }
      ]
    },
    {
      path: 'miniprogram-code',
      name: 'MiniprogramCode',
      component: () => import('../views/my/miniprogram-code.vue'),
      meta: { title: '我的专属码' }
    },
    {
      path: 'integral',
      name: 'Integral',
      component: () => import('../views/my/integral.vue'),
      meta: {
        title: '我的积分'
      },
      children: [{
        path: 'customer',
        name: 'Customer',
        component: () => import('../views/my/integral/customer.vue'),
        meta: {
          title: '添加客户'
        },
        children: [{
          path: 'add-brand',
          name: 'AddBrand',
          component: () => import('../views/my/integral/add-brand.vue'),
          meta: {
            title: '添加品牌'
          }
        }]
      },
      {
        path: 'my-customer',
        name: 'MyCustomer',
        component: () => import('../views/my/integral/my-customer.vue'),
        meta: {
          title: '我的客户'
        },
        children: [{
          path: 'add-brand',
          name: 'CustomerAddBrand',
          component: () => import('../views/my/integral/add-brand.vue'),
          meta: {
            title: '添加品牌'
          }
        }]
      },
      {
        path: 'integral-detail',
        name: 'IntegralDetail',
        component: () => import('../views/my/integral/integral-detail.vue'),
        meta: {
          title: '积分明细'
        }
      }
      ]
    },
    {
      path: 'coupon',
      name: 'Coupon',
      component: () => import('../views/my/coupon.vue'),
      meta: {
        title: '我的优惠券'
      },
      children: [{
        path: 'coupon-detail',
        name: 'CouponDetail',
        component: () => import('../views/my/coupon/coupon-detail.vue'),
        meta: {
          title: '我的优惠券'
        },
        children: [{
          path: 'use-coupon',
          name: 'UseCouponDetail',
          component: () => import('../views/my/coupon/use-coupon.vue'),
          meta: {
            title: '我的优惠券'
          }
        }]
      },
      {
        path: 'use-coupon',
        name: 'UseCoupon',
        component: () => import('../views/my/coupon/use-coupon.vue'),
        meta: {
          title: '我的优惠券'
        }
      }
      ]
    },
    {
      path: 'exchange-center',
      name: 'ExchangeCenter',
      component: () => import('../views/my/exchange-center.vue'),
      meta: {
        title: '兑换中心'
      },
      children: [{
        path: 'integral-goods',
        name: 'IntegralGoods',
        component: () => import('../views/my/exchange-center/integral-goods.vue'),
        meta: {
          title: '积分商品'
        },
        children: [{
          path: 'order',
          name: 'Order',
          component: () => import('../views/my/exchange-center/order.vue'),
          meta: {
            title: '确认兑换'
          },
          children: [
            {
              path: 'address-list',
              name: 'AddressList',
              component: () => import('../views/my/exchange-center/address-list.vue'),
              meta: { title: '地址管理' },
              children: [
                {
                  path: 'edit-address',
                  name: 'EditAddress',
                  component: () => import('../views/my/exchange-center/edit-address'),
                  meta: {
                    title: '编辑地址'
                  }
                }
              ]
            },
            {
              path: 'order-detail',
              name: 'OrderDetail',
              component: () => import('../views/my/exchange-center/order-detail.vue'),
              meta: {
                title: '订单详情'
              },
              children: [{
                path: 'check-logistics',
                name: '查看物流',
                component: () => import('../views/my/exchange-center/check-logistics')
              }]
            }
          ]
        }]
      }, {
        path: 'order-detail',
        name: 'OrderDetail',
        component: () => import('../views/my/exchange-center/order-detail.vue'),
        meta: {
          title: '订单详情'
        },
        children: [{
          path: 'check-logistics',
          name: '查看物流',
          component: () => import('../views/my/exchange-center/check-logistics')
        }]
      }]
    },
    {
      path: 'poster',
      name: 'MyPoster',
      component: () => import('../views/designer/poster.vue'),
      meta: {
        title: '权益海报'
      }
    },
    {
      path: 'park',
      name: 'Park',
      component: () => import('../views/my/park.vue'),
      meta: {
        title: '免费停车'
      }
    },
    {
      path: 'my-homepage',
      name: 'MyHomePage',
      component: () => import('../views/my/my-homepage.vue'),
      meta: {
        title: '我的主页'
      },
      children: [{
        path: 'case-detail',
        name: 'MyHomePageDetail',
        component: () => import('../views/my/my-homapage/case-detail.vue'),
        meta: {
          title: '设计师主页'
        },
        children: [
          {
            path: 'release',
            name: 'HomePageRelease',
            component: () => import('../views/my/my-homapage/release.vue'),
            meta: { title: '编辑作品' }
          }
        ]
      },
      {
        path: 'edit-msg',
        name: 'EditMsg',
        component: () => import('../views/my/my-homapage/edit-msg.vue'),
        meta: {
          title: '编辑资料'
        }
      },
      {
        path: 'release',
        name: 'Release',
        component: () => import('../views/my/my-homapage/release.vue'),
        meta: {
          title: '发布作品'
        }
      }
      ]
    },
    {
      path: 'activity',
      name: 'MyActivity',
      component: () => import('../views/my/activity.vue'),
      meta: {
        title: '我的活动'
      },
      children: [{
        path: 'activity-detail',
        name: 'MyActivityDetail',
        component: () => import('../views/home/activity/detail.vue'),
        meta: {
          title: '活动详情'
        }
      }]
    },
    {
      path: 'task',
      name: 'Task',
      component: () => import('../views/my/task.vue'),
      meta: {
        title: '任务中心'
      },
      children: [{
        path: 'integral-detail',
        name: 'TaskIntegralDetail',
        component: () => import('../views/my/integral/integral-detail.vue'),
        meta: '积分明细'
      }
      ]
    },
    {
      path: 'my-custom',
      name: 'MyCustom',
      component: () => import('../views/my/my-custom.vue'),
      meta: {
        title: '我的客户'
      },
      children: [{
        path: 'custom-detail',
        name: 'CustomDetail',
        component: () => import('../views/my/integral/my-customer.vue'),
        meta: {
          title: '我的客户'
        },
        children: [{
          path: 'add-brand',
          name: 'CustomAddBrand',
          component: () => import('../views/my/integral/add-brand.vue'),
          meta: {
            title: '添加品牌'
          }
        }]
      },
      {
        path: 'add-custom',
        name: 'AddCustom',
        component: () => import('../views/my/integral/customer.vue'),
        meta: {
          title: '添加客户'
        },
        children: [{
          path: 'add-brand',
          name: 'MyCustomAddBrand',
          component: () => import('../views/my/integral/add-brand.vue'),
          meta: {
            title: '添加品牌'
          }
        }]
      }
      ]
    },
    {
      path: 'counsel',
      name: 'Counsel',
      component: () => import('../views/my/counsel.vue'),
      meta: {
        title: '咨询客户'
      }
    },
    {
      path: 'reservation',
      name: 'Reservation',
      component: () => import('../views/my/reservation.vue'),
      meta: { title: '我的预约' }
    }
    ]
  }]
}, {
  path: '/login',
  name: 'Login',
  component: () => import('../views/login/login.vue'),
  meta: {
    title: '登录'
  },
  children: [{
    path: 'login-phone',
    name: 'LoginPhone',
    component: () => import('../views/login/login-phone.vue'),
    meta: {
      title: '手机验证码登录'
    }
  }]
}, {
  path: '/sign-in',
  name: 'SignIn',
  component: () => import('../views/sign/sign-in.vue'),
  meta: { title: '签到主页' }
}

]
const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  // scrollBehavior: () => ({
  //   y: 0
  // }),
  routes: routes
})
const router = createRouter()
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  // 如果用户未能验证身份，则 `next` 会被调用两次
  next()
})

export default router
